package com.smallA.utils;

import com.smallA.po.Exam;
import com.smallA.po.Grade;
import com.smallA.vo.ResultExam;
import com.smallA.vo.ResultTest;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 返回前端数据转化器
 */
public class TypeConverterUtils {

    public static List<ResultTest> converterResultTest(List<Grade> grades) {
        if (grades == null || grades.size() == 0) {
            return null;
        }
        List<ResultTest> list = new ArrayList<>();
        for (Grade grade : grades) {
            Date submissionTime = null;
            Date beginTime = grade.getBeginTime();
            if (beginTime != null) {
                int useTime = grade.getUseTime();
                submissionTime = new Date(beginTime.getTime() + useTime * 60 * 1000);
            }
            ResultTest resultTest = new ResultTest(grade.getId(),
                    grade.getTest().getExamId(),
                    grade.getTest().getContext(),
                    grade.getTest().getBeginDate(),
                    submissionTime,
                    grade.getTest().getTestTime(),
                    grade.getStudentId(),
                    grade.getScore(),
                    grade.getType());
            list.add(resultTest);
        }
        return list;
    }

    public static ResultExam converterResultExam(Exam exam, String testName) {
        if (exam == null || testName == null) {
            return null;
        }
        return new ResultExam(exam.getId(),
                testName,
                exam.getTeacherId(),
                exam.getAnalyzes(),
                exam.getDifficulty(),
                exam.getScore(),
                exam.getQuestions());
    }


}
